using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using NUnit.Framework;
public partial class TraCuu : System.Web.UI.Page
{
    clsxuly xuly = new clsxuly();
    DataTable tbl = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Request.QueryString["ma"] != null)
        //{
            BindGrid();
       // }

    }
    [Test]
    public void kiemtrarong()
    {
        
        Assert.IsTrue(xuly.GioiThieu()!= 1, "Basic smoke test of test1.aspx didn't find 'Hello' in response!");
    }
    protected void BindGrid()
    {
        if (Request.QueryString["ma"] != null)
        {
            if (txttukhoa.Text == "")
            {
                string ma = Request.QueryString["ma"].ToString();
                tbl = xuly.TimTheLoai(ma.Trim());
                if (tbl.Rows.Count == 0)
                {
                    thongbao.Text= "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                    GridView1.Controls.Clear();
                }
                else
                {
                    thongbao.Text ="Have "+ tbl.Rows.Count +" result!";
                    GridView1.DataSource = tbl;
                    GridView1.DataBind();
                }
            }
            else
            {
                
                if (cbochontracuu.Text == "TatCa")
                {
                    tbl = xuly.TimTatCa(txttukhoa.Text.Trim());
                    if (tbl.Rows.Count == 0)
                    {
                        thongbao.Text = "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                        GridView1.Controls.Clear();
                    }
                    else
                    {
                        thongbao.Text = "Have " + tbl.Rows.Count + " result";
                        GridView1.DataSource = tbl;
                        GridView1.DataBind();
                    }
                }
                if (cbochontracuu.Text == "TacGia")
                {
                    tbl = xuly.TimTacGia(txttukhoa.Text.Trim());
                    if (tbl.Rows.Count == 0)
                    {
                        thongbao.Text = "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                        GridView1.Controls.Clear();
                    }
                    else
                    {
                        thongbao.Text = "Have " + tbl.Rows.Count + " result";
                        GridView1.DataSource = tbl;
                        GridView1.DataBind();
                    }
                }
                if (cbochontracuu.SelectedValue == "TieuDe")
                {
                    tbl = xuly.TimTieuDeSach(txttukhoa.Text.Trim());
                    if (tbl.Rows.Count == 0)
                    {
                        thongbao.Text = "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                        GridView1.Controls.Clear();
                    }
                    else
                    {
                        thongbao.Text = "Have " + tbl.Rows.Count + " result";
                        GridView1.DataSource = tbl;
                        GridView1.DataBind();
                    }
                }
                if (cbochontracuu.Text == "DKCB")
                {
                    tbl = xuly.TimDKCB(txttukhoa.Text.Trim());
                    if (tbl.Rows.Count == 0)
                    {
                        thongbao.Text = "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                        GridView1.Controls.Clear();
                    }
                    else
                    {
                        thongbao.Text = "Have " + tbl.Rows.Count + " result";
                        GridView1.DataSource = tbl;
                        GridView1.DataBind();
                    }
                }
            }

        }
        else
        {
            if (txttukhoa.Text == "")
            {
                //thongbao.Text = "Please input complete information !";
            }
            else
            {
                if (cbochontracuu.Text == "TatCa")
                {
                    tbl = xuly.TimTatCa(txttukhoa.Text.Trim());
                    if (tbl.Rows.Count == 0)
                    {
                        thongbao.Text = "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                        GridView1.Controls.Clear();
                    }
                    else
                    {
                        thongbao.Text = "Have " + tbl.Rows.Count + " result";
                        GridView1.DataSource = tbl;
                        GridView1.DataBind();
                    }
                }
                if (cbochontracuu.Text == "TacGia")
                {
                    tbl = xuly.TimTacGia(txttukhoa.Text.Trim());
                    if (tbl.Rows.Count == 0)
                    {
                        thongbao.Text = "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                        GridView1.Controls.Clear();
                    }
                    else
                    {
                        thongbao.Text = "Have " + tbl.Rows.Count + " result";
                        GridView1.DataSource = tbl;
                        GridView1.DataBind();
                    }
                }
                if (cbochontracuu.SelectedValue == "TieuDe")
                {
                    tbl = xuly.TimTieuDeSach(txttukhoa.Text.Trim());
                    if (tbl.Rows.Count == 0)
                    {
                        thongbao.Text = "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                        GridView1.Controls.Clear();
                    }
                    else
                    {
                        thongbao.Text = "Have " + tbl.Rows.Count + " result";
                        GridView1.DataSource = tbl;
                        GridView1.DataBind();
                    }
                }
                if (cbochontracuu.Text == "DKCB")
                {
                    tbl = xuly.TimDKCB(txttukhoa.Text.Trim());
                    if (tbl.Rows.Count == 0)
                    {
                        thongbao.Text = "<br/>No result ! This topic is updating . You can search with another topic.Thanks!";
                        GridView1.Controls.Clear();
                    }
                    else
                    {
                        thongbao.Text = "Have " + tbl.Rows.Count + " result";
                        GridView1.DataSource = tbl;
                        GridView1.DataBind();
                    }
                }

            }

        }


    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView1.PageIndex = e.NewPageIndex;
        BindGrid();


    }
    protected void btntim_Click(object sender, EventArgs e)
    {
        if (txttukhoa.Text != "")
        {
            
            if (cbochontracuu.SelectedValue == "TatCa")
            {
                BindGrid();
            }
            if (cbochontracuu.SelectedValue == "TacGia")
            {
                BindGrid();
            }

            if (cbochontracuu.SelectedValue == "TieuDe")
            {
                BindGrid();
            }

            if (cbochontracuu.SelectedValue == "DKCB")
            {
                BindGrid();
            }
            if (cbochontracuu.SelectedValue == "MuonNhieu")
            {
                BindGrid();

            }
        }
        else
        {
            Response.Redirect("Tracuu.aspx");
        }
    }
    protected void cbochontracuu_SelectedIndexChanged(object sender, EventArgs e)
    {
        //if (cbochontracuu.SelectedValue == "MuonNhieu")
        //{
        //    Label1.Visible = false;
        //    txttukhoa.Visible = false;
        //}
        //else
        //{
        //    Label1.Visible = true;
        //    txttukhoa.Visible = true;
        //}
    }
}
